package com.longqinuo.mycarservice.utils;

import android.os.AsyncTask;
import android.widget.Button;

import com.longqinuo.mycarservice.R;


/**
 * Created by zxw on 2016/7/1.
 */
public class GetTestCode {
    private static Button mGet;
    public static void waitNextClick(Button getCode) {
        mGet = getCode;
        new AsyncTask<Void, Integer, Void>() {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                mGet.setBackgroundResource(R.drawable.btn_wait_code);
                mGet.setClickable(false);
            }

            @Override
            protected Void doInBackground(Void... params) {  //仅此方法是执行在后台线程中不能再这里修改UI 其他方法都执行在主线程中可以修改UI
                //模拟进度更新
                for (int i = 60; i > 0; i--) {
                    publishProgress(i);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                return null;
            }

            @Override
            protected void onProgressUpdate(Integer... values) {
                //获取进度更新
                super.onProgressUpdate(values);
                mGet.setText(values[0] + "s");

            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                mGet.setBackgroundResource(R.drawable.btn_get_code);
                mGet.setClickable(true);
                mGet.setText("获取验证码");
            }
        }.execute();
    }
}
